//
//  ResetPwdView.m
//  MUBATE
//
//  Created by sunbin on 2017/2/15.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "ResetPwdView.h"

@interface ResetPwdView()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UILabel *rememberLab;

@property (weak, nonatomic) IBOutlet UILabel *rememberBbottom;
@property (weak, nonatomic) IBOutlet UIView *nav;

@end

@implementation ResetPwdView

- (void)awakeFromNib{
    // 设置label
    [NHUtils setLabel:_rememberLab text:NSLocalizedString(@"Remember me ~", @"Remember me ~") textColor:[UIColor alertTextColor] font:Launch_welcomeFon];
    [NHUtils setLabel:_rememberBbottom text:NSLocalizedString(@"Ha ha", @"Ha ha") textColor:[UIColor alertTextColor] font:Launch_comeBackFon];
    
    // 设置文本输入框
    [_newpwd leftViewModeWithConstrainedToWidth:200.f text:NSLocalizedString(@"new Password", @"new Password") fon:Launch_textLeftViewFon setFont:Launch_textFon leftTextColor:[UIColor leftTextColor] bodyTextColor:[UIColor bodyTextColor] PlaceholderColor:[UIColor PlaceholderColor] setPlaceholder:nil isLaunch:YES];
    [_pwd leftViewModeWithConstrainedToWidth:200.f text:NSLocalizedString(@"confirm password", @"confirm password") fon:Launch_textLeftViewFon setFont:Launch_textFon leftTextColor:[UIColor leftTextColor] bodyTextColor:[UIColor bodyTextColor] PlaceholderColor:[UIColor PlaceholderColor] setPlaceholder:nil isLaunch:YES];
    
    [NHUtils setButton:_confirmBtn isLaunch:YES setTitle:NSLocalizedString(@"confirm", @"confirm") setLayerCornerRadius:0 setFont:Launch_confirmBtnFon];
    _confirmBtn.enabled = NO;
}

+ (instancetype)LoadResetPwdView{
    ResetPwdView *resetPwdView = [self loadFromNib];
    return resetPwdView;
}

+ (instancetype)loadFromNib{
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"ResetPwdView" owner:nil options:nil];
    return [objects lastObject];
}







- (IBAction)btnEven:(UIButton *)sender {
    NSInteger tag = sender.tag-10;
    if (_nextStepHandler) {
        _nextStepHandler(_newpwd.text ,tag ,[NHUtils enterPwd:_pwd.text resentPwd:_newpwd.text]);
    }
}



- (IBAction)editingChanged:(UITextField *)sender {

    _confirmBtn.enabled = (![NHUtils isBlankString:_pwd.text] && ![NHUtils isBlankString:_newpwd.text])&&[_pwd.text checkPassWord]&&[_newpwd.text checkPassWord];
}


#pragma make -UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    NSInteger index = textField.tag;
    if (index == 2) {
        _nav.hidden = YES;
    }
    return YES;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    _nav.hidden = NO;

    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    if (_confirmBtn.enabled) {
        //确认按钮
        [self btnEven:_confirmBtn];
  
    }else {
        [_pwd becomeFirstResponder];
    }
    return YES;
}

@end
